package code.main.controller.table
{
	import code.main.view.table.ChipsDisplay;
	
	import com.greensock.TweenLite;
	import com.greensock.easing.Circ;
	import com.yy.tools.arry.ArrayTools;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;

	/**
	 *筹码控制器 
	 * @author YY
	 * 
	 */
	public class ChipsCtrl
	{
		
		//玩家收发筹码位置
		private var _seatsPos:Array = [
			[604,156],
			[700,320],
			[604,478],
			[384,545],
			[160,478],
			[64,320],
			[160,156]
		];
		//玩家奖池位置
		private var _chipsPos:Array = [
			[477,187],
			[521,312],
			[485,374],
			[378,423],
			[249,364],
			[228,302],
			[287,187]
		];
		private var _chipsList:Array;//奖池列表
		private var _chipsPanle:DisplayObjectContainer;
		public function ChipsCtrl(ctn:DisplayObjectContainer)
		{
			_chipsPanle = ctn;
			init();
		}
		private function init():void {
			_chipsList = [];
			var i:int;
			var len:int = _chipsPos.length;
			for(i=0; i<len; i++) {
				_chipsList.push(new ChipsDisplay(_chipsPanle, _chipsPos[i][0],_chipsPos[i][1]));
			}
		}
		
		/**
		 *玩家下注 
		 * 
		 * @param seatId 座位id
		 * @param betValue 注值
		 * @param callBack 注值
		 * 
		 */
		public function playerBet(seatId:int, betValue:Number, callBack:Function=null):void {
			seatId--;
			var cd:ChipsDisplay = _chipsList[seatId]; 
			var pos:Array = _seatsPos[seatId];
			cd.moveChipsToPot(betValue,pos, callBack);
		}
		
		/**
		 *销毁下注筹码信息 
		 * 
		 */
		public function disposePlayerBet():void {
			for(var i:uint=0; i<_chipsList.length; i++) 
			{
				var tempChipDisplay:ChipsDisplay=_chipsList[i];//  .push(new ChipsDisplay(_chipsPanle, _chipsPos[i][0],_chipsPos[i][1]));
				tempChipDisplay.chipDispose();
			}
		}
		
		
		/**
		 *奖池筹码移动到玩家 
		 * @param potId 奖池的id
		 * @param playerId 要移动到的玩家的id
		 * @param callBack
		 * 
		 */
		public function potToPlayer(potId:int, seatId:int, callBack:Function):void {
			seatId--;
			potId --;
			var cd:ChipsDisplay = _chipsList[potId]; 
			var pos:Array = _seatsPos[seatId];
			cd.movePotChipsToUser(callBack, pos);
		}
		
		/**
		 *显示注池 
		 * @param seatId
		 * @param value
		 * 
		 */
		public function showChips(seatId:int, value:Number):void {
			seatId--;
			var cd:ChipsDisplay = _chipsList[seatId]; 
			cd.moveChipsToPot(value);
		}
	}
}